package xin.marcher.module.rights.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.rights.api.PermissionApi;
import xin.marcher.module.rights.domain.request.PermissionRequest;
import xin.marcher.module.rights.domain.request.QueryPermissionRequest;
import xin.marcher.module.rights.domain.request.RemovePermissionRequest;
import xin.marcher.module.rights.support.LoginUserHolder;

/**
 *
 */
@RestController
@RequestMapping("/rights/permission")
public class PermissionController {

    @Autowired
    private PermissionApi permissionApi;

    /**
     * 添加权限接口
     */
    @PreAuthorize("@rights.check('savePermission')")
    @PostMapping("/savePermission")
    public JsonResult savePermission(@RequestBody PermissionRequest request) {
        System.out.println(LoginUserHolder.getLoginUser());
        return permissionApi.savePermission(request);
    }

    /**
     * 删除权限接口
     */
    @PreAuthorize("@rights.check('removePermission')")
    @PostMapping("/removePermission")
    public JsonResult removePermission(@RequestBody RemovePermissionRequest request) {
        return permissionApi.removePermission(request);
    }

    /**
     * 查询权限列表接口
     */
    @PreAuthorize("@rights.check('queryPermission')")
    @PostMapping("/queryPermission")
    public JsonResult queryPermission(@RequestBody QueryPermissionRequest request) {
        return permissionApi.queryPermission(request);
    }

}
